<?php
class Db{

    public $conn;
    public $dbname = "month11";
    public $user = "root";
    public $password = "root";
    public $host = "localhost";

    //这是连接数据库的构造方法
    public function __construct()
    {
        $this -> conn = mysqli_connect($this->host,$this->user,$this->password,$this->dbname);
    }

    //这个是添加数据的封装方法add
    public function add($table,$data){
        $res = $this -> conn -> query("insert into $table values ('null','".$data['num']."','".$data['name']."','".$data['people']."','".$data['tel']."','".$data['content']."')");
        return $res;

    }

    //这个是显示数据的封装方法show
    public function show($table){
        $data = $this -> conn -> query("select * from $table");
        $arr = array();
        while ($row = mysqli_fetch_assoc($data)){
            array_push($arr,$row);
        }
        return $arr;
    }

    //这个是删除数据的封装方法del
    public function del($table,$id){
        $res = $this -> conn -> query("delete from $table where id = '".$id."'");
        return $res;

    }

    //这个是修改数据的封装方法upd
    public function upd($table,$name,$id){
        $res = $this -> conn -> query("update $table set name = '".$name."' where id = '".$id."'");
        return $res;
    }


}